<?php

namespace Library;

abstract class Auth extends View {

	private static $_auths = array();

	public function __construct() {
	}

	public static function get( $kind ) {
		if( !isset(self::$_auths[$kind]) ) {
			$class = '\Library\Auth\\' . $kind . 'Auth';
			self::$_auths[$kind] = new $class();
		}
		return self::$_auths[$kind];
	}
	
	public function isChangeable( \Bean\User $user = null ) {
		return $this->getUser() && $this->getUser()->is( $user );
	}
	
	public abstract function getUser();
	
	public abstract function check( $data );
	
	public abstract function create( $data );
	
	public abstract function authenticate( $data );
	
	public abstract function change( $data );

	public function getView() {
		$view = strtr( get_class($this), '\\', '/' );
		$view = substr( $view, strpos( $view, '/' ) + 1 );
		return 'Widget/' . $view;
	}
}
